package com.jk.controller;

import com.alipay.api.AlipayApiException;
import com.jk.entity.AlipayBean;
import com.jk.service.PayService;
import com.jk.utils.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
@CrossOrigin(origins = "*")
public class PayController {

    @Autowired
    private PayService payService;

    /**
     * 阿里支付
     * @param
     * @param
     * @param
     * @param
     * @return
     * @throws AlipayApiException
     */
    @RequestMapping( "alipay")
    public String alipay(AlipayBean alipayBean,Integer useerId) throws AlipayApiException {
        AlipayBean alipay = new AlipayBean();
        long alipayID = SnowFlake.nextId();

        alipay.setOut_trade_no(alipayID);
        alipay.setSubject(alipayBean.getSubject());
        alipay.setTotal_amount(alipayBean.getTotal_amount());
        alipay.setState(alipayBean.getState());
        alipay.setPserial(alipayBean.getPserial());
        return payService.aliPay(alipay,useerId);

    }

}
